﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Net;
using SoccerScore.Compact.Linq;
using System.Linq;
using System.Data.SqlServerCe;
using HtmlAgilityPack;
using System.Data.SqlClient;
using Soccer_Score_Forecast.BulkSql;

namespace Soccer_Score_Forecast
{
    public partial class Form1 : Form
    {
        #region 软件加密模块2，注册验证码不正确不能入库
        private void toolStripButton_iniToday_Click(object sender, EventArgs e)
        {
            toolStripLabel1.Text = "updateLiveTable";

            try
            {
                this.tabControl1.SelectedTab = this.tabPage1;

                insertComplete = false;

                WebLiveDataGet();
                //button1.PerformClick(); //执行及时网页采集

                while (!insertComplete) Application.DoEvents();

                //if (ls.bRegOK)
                //{
                int pb = Int32.Parse(toolStripLabel2.Text);
                toolStripProgressBar1.Maximum = pb;

                using (SevenmLiveToSql sevenm = new SevenmLiveToSql())
                {
                    string sm = sevenm.UpdateTodayMatch();
                    toolStripLabel2.Text = sm; Thread.Sleep(1);
                }

                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                textBox1.Text = aboutblank;
            }
        }
        #endregion
        #region 自动升级系统
        private void toolStripButton_autoUpateSystem_Click(object sender, EventArgs e)
        {
            //AutoUpdate.FrmUpdate autoupdateform = new AutoUpdate.FrmUpdate();
            //autoupdateform.ShowDialog();

            toolStripLabel1.Text = "statSimulink";

            this.tabControl1.SelectedTab = this.tabPage2;

            Application.DoEvents();

            //button3.PerformClick();

            initAnalysisReview();

            this.tabControl1.SelectedTab = this.tabPage2;

        }
        #endregion

        LicenseCheck lc = new LicenseCheck();
        private void 注册LicenseCheck()
        {
            string appPath = Application.StartupPath.ToString();
            string licPath = appPath + "\\machine.lic";
            LicenseReadLib lr = new LicenseReadLib(ls, lc);
            if (lr.ReadLicense(licPath))
            {
                if (lr.CheckLicenseUse())
                {
                    if (lr.CheckLicenseSeries())
                    {
                        if (lr.CheckLicenseDate())
                        {
                            if (lr.CheckLicenseTimes()) { lr.WriteLicense(licPath); }
                            else { this.Close(); Application.ExitThread(); Application.Exit(); }
                        }
                        else
                        { this.Close(); Application.ExitThread(); Application.Exit(); }
                    }
                    else
                    { this.Close(); Application.ExitThread(); Application.Exit(); }
                }
                else
                { this.Close(); Application.ExitThread(); Application.Exit(); }
            }
            else
            { this.Close(); Application.ExitThread(); Application.Exit(); }
        }
        private void 校验注册号代码Btn_Click()
        {
            //检验注册号，把检验结果找一内存保存起来。不要在校验结果代码附近做任何影响程序正常工作的处理，这样不易被跟踪。
            string regTail3 = lc.GetRegTail3ByMac(ls.regDateFile);
            if (string.Compare(regTail3, 0, ls.regLicense, 12, 17) == 0)
                ls.bRegOK = true;
            else
                ls.bRegOK = false;
        }
        private int 核心功能代码代表Btn_Click()
        {
            int result;
            if (ls.bRegOK)
            {
                result = 10 + 10;
            }
            else
            {
                result = 10 + 10 + 1;  //发现注册码正常的标记为false时,对核心功能代码进行不易发觉的修改，导致结果无法使用，注：不要弹出易被跟踪的消息事件等。
            }
            return result;
        }

        #region 软件加密模块1,检验注册码
        private void Form1_Load(object sender, EventArgs ee)
        {


            注册LicenseCheck();
            dataGridView5.Visible = false;
            toolStripStatusLabel2.Text = dateTimePicker2.Value.ToString("yyyy-MM-dd");//日历组建日期字符串格式化方法
            DateTime? dt, dt1;
            using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
            {
                dt = matches.Result_tb_lib.Max(p => p.Match_time);
                if (dt != null)
                    toolStripStatusLabel3.Text = dt.ToString();
                else
                    toolStripStatusLabel3.Text = "2002.1.1";

                dt1 = matches.live_Table_lib.Max(p => p.match_time);
                toolStripStatusLabel4.Text = dt1.HasValue ? dt1.Value.ToString() : null;
            }
            treeView5.Nodes.Clear();

            //loaddatatree.TreeViewMatch(treeView5, "type");


            dateTimePicker1.Value = DateTime.Parse(toolStripStatusLabel3.Text);
            textBox2.Text = "1";


            this.tabControl1.SelectedTab = this.tabPage2;

        }
        LincenseString ls = new LincenseString();

        #endregion

    }
}
